<?php
/******************************************************************************
 *
 *    OpenZoowa - Web App to manage events
 *    Copyright (C) 2008 Jesus Ruiz-Ayucar
 *
 *    This program is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU Affero General Public License as
 *    published by the Free Software Foundation, either version 3 of the
 *    License, or (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *****************************************************************************/
   // Loading config
   require_once('config.php');

   // Getting controller
   if (isset($_GET['c'])) {

      // Cleaning input
      $pat = array('/\.+/', '/\/+/');
      $rep = array('','');
      $controller = preg_replace($pat, $rep, $_GET['c']);

      if (file_exists(controllerspath . $controller.'.php')) {
         require_once(controllerspath . $controller.'.php');

         // First controller char to upper
         $name = ucwords($controller).'Controller';
         $controller = new $name();

         if (isset($_GET['a'])) {
            $method = $_GET['a'];
         } else {
            $method = 'index';
         }

         if(method_exists($controller, $method)) {
            $controller->$method();
         } else {
            // If there is not such method, then raise 404
            echo "404";
         }
      } else {
         // If there is not such controller, then raise 404
         echo "404";
      }
   } else {
      // Default action
      require_once(controllerspath . 'event.php');
      $controller = new EventController();
      $controller->index();
   }
?>